<!DOCTYPE html>
<html>
<head>
    <title>Supply</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <link  href="<?php echo base_url();?>css/admin.css" rel="stylesheet" type="text/css" />
     <!-- JS2CAL -->
	<link rel="stylesheet" type="text/css" href="<?php echo base_url();?>css/jscal2/jscal2.css" />
    <link rel="stylesheet" type="text/css" href="<?php echo base_url();?>css/jscal2/border-radius.css" />
    <link rel="stylesheet" type="text/css" href="<?php echo base_url();?>css/jscal2/steel/steel.css" />
    <script type="text/javascript" src="<?php echo base_url();?>js/jscal2/jscal2.js"></script>
    <script type="text/javascript" src="<?php echo base_url();?>js/jscal2/lang/th.js"></script>

</head>
<body>

 <div id="contentright">
        <div id="search">
          <div id="searchblank">
            <div id="searchinput">
             Welcome, admin
            </div>
          
            <div id="advancesearch"><a href="#" class="advancesearch">Logout</a></div>
          </div>
        </div>
        </div>
    <div id="main">
      <?php 
        $menu['nowmenu'] = 'exportcsv';
        $this->load->view('common/divheader',$menu);
        ?>
        <div id="middle">
        <div id="breadcrumbs"><a href="dashboard.html">Dashboard</a>/ Supplies/ Supply payment</div>
            <?php $this->load->view('manager/divleftmenu');?>
            <div id="center-column">
      
            <form action="<?php echo site_url('truckacc/exportCSV');?>" method="post">
                <div class="top-bar">
                    
                    <h1>Supply data to WINSpeed</h1>
                    
              </div>
                <div class="select-bar">
                    <p>
                      <input size="30" id="f_date1" name="date" value="<?=$date;?>" /><button id="f_btn1">...</button>
                      <script type="text/javascript">//<![CDATA[

      var SELECTED_RANGE = null;
      function getSelectionHandler() {
              var startDate = null;
              var ignoreEvent = false;
              return function(cal) {
                      var selectionObject = cal.selection;

                      // avoid recursion, since selectRange triggers onSelect
                      if (ignoreEvent)
                              return;

                      var selectedDate = selectionObject.get();
                      if (startDate == null) {
                              startDate = selectedDate;
                              SELECTED_RANGE = null;
                              document.getElementById("info").innerHTML = "Click to select end date";

                              // comment out the following two lines and the ones marked (*) in the else branch
                              // if you wish to allow selection of an older date (will still select range)
                              cal.args.min = Calendar.intToDate(selectedDate);
                              cal.refresh();
                      } else {
                              ignoreEvent = true;
                              selectionObject.selectRange(startDate, selectedDate);
                              ignoreEvent = false;
                              SELECTED_RANGE = selectionObject.sel[0];

                              // alert(SELECTED_RANGE.toSource());
                              //
                              // here SELECTED_RANGE contains two integer numbers: start date and end date.
                              // you can get JS Date objects from them using Calendar.intToDate(number)

                              startDate = null;
                              document.getElementById("info").innerHTML = selectionObject.print("%Y-%m-%d") +
                                      "<br />Click again to select new start date";

                              // (*)
                              cal.args.min = null;
                              
                              cal.refresh();
                              
         
                      }
              };
      };

      Calendar.setup({
              //cont          : "cont",
		     inputField : "f_date1",
		     trigger    : "f_btn1",
		     max: <?php echo date('Ymd');?>,
             fdow          : 1,
             selectionType : Calendar.SEL_SINGLE,
             onSelect      : getSelectionHandler()
      });

    //]]></script>
                      <input type="submit" name="oksubmit" value="OK" />
                    </p>
              </div>
                <div class="table">
                    <table class="listing" cellpadding="0" cellspacing="0">
                        <tr>
                            <?php 
    			foreach ($headertable as $head):
    		?>
    			<th><?php echo $head;?></th>
    		<?php 	
    			endforeach;
    		?>
                        </tr>
                        <?php 
				$allsum = array('posname'=>'',
								'sumqty'=>0,
								'cost_unt'=>0,
								'sumdiscount'=>0,
								'sumamount'=>0,
								'cashamount'=>0,
								'sumpromo'=>0,
								'sumcashpromo'=>0,);
    			foreach ($resultarray as $row):
    		?>
    				<tr>
    					<?php 
    						foreach ($row as $key => $eadata):
    					?>
    						<td class="style2"><?php echo $eadata;?></td>
			    		<?php 	
							$allsum[$key] += $eadata;
			    			endforeach;
			    		?>
    				</tr>
    		<?php 	
    			endforeach;
    		?>
                        
                           <tr>
                            <th class="listing2">Total</th>
                            <th><?=$allsum['sumqty']?></th>
                            <th></th>
                            <th><?=$allsum['sumamount']?></th>
                            <th><?=$allsum['sumdiscount']?></th>
							<th><?=$allsum['cashamount']?></th>
							<th><?=$allsum['sumpromo']?></th>
							<th><?=$allsum['sumcashpromo']?></th>
                        </tr>
                    </table>
                    
              </div>
              <div class="select-bar">
                    <p>
                      partnum:<input type="text" name="partnum" value="<?=$partnum;?>"/>
                    </p>
                    <p>
                      partname:<input type="text" name="partname" value="<?=$partname;?>"/>
                    </p>
                    <p>
                      depcode:<input type="text" name="depcode" value="<?=$depcode;?>"/>
                    </p>
              </div>
              
              <div class="top-bar">
                    <input type="submit" name="gensubmit" value="export CSV" class="button"/>
                    <h1>&nbsp;</h1>
                    
              </div>
              </form>
            </div>
            <div id="right-column">
                <strong class="h">Quick info</strong>
                <div class="box">
                  <p>1. เลือกช่วงวันที่ต้องการ download ข้อมูล<br>
                เช่น ข้อมูลวันที่ 12 ให้เลือก 2011-01-12 -&gt; 2011-01-12</p>
                  <p>2. กรอก Partnum </p>
                  <p>3. คลิกปุ่ม download</p>
                </div>
            </div>
        </div>
        <div id="footer"><p>ALL RIGHTS RESERVED 2012 <a href="http://www.ubonbioethanol.com">UBON BIO ETHANOL CO., LTD.</a><br>Developed by DASH CO., LTD (2011-2012).  </p></div>
    </div>
</body>
</html>